<!DOCTYPE html>
<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>西河东河</title>
    <script type="text/javascript">
        //在此拿到jsAPI权限验证配置所需要的信息
        var _config = <%= com.alibaba.dingtalk.openapi.demo.auth.AuthHelper.getConfig(request) %>;
        //alert(_config);
    </script>
    <script type="text/javascript" src="javascripts/zepto.min.js"></script>
    <script type="text/javascript" src="http://g.alicdn.com/dingding/open-develop/1.6.9/dingtalk.js">
    </script>
    <script type="text/javascript" src="javascripts/logger.js">
    </script>

    <script type="text/javascript">

        dd.config({
            agentId : _config.agentid,
            corpId : _config.corpId,
            timeStamp : _config.timeStamp,
            nonceStr : _config.nonceStr,
            signature : _config.signature,
            jsApiList : [ 'runtime.info', 'biz.contact.choose',
                'device.notification.confirm', 'device.notification.alert',
                'device.notification.prompt', 'biz.ding.post',
                'biz.util.openLink' ]
        });


        dd.ready(function() {
            dd.biz.navigation.setTitle({
                title: '钉钉demo',
                onSuccess: function(data) {
                },
                onFail: function(err) {
                    log.e(JSON.stringify(err));
                }
            });

            dd.runtime.info({
                onSuccess : function(info) {
                    logger.e('runtime info: ' + JSON.stringify(info));
                },
                onFail : function(err) {
                    logger.e('fail: ' + JSON.stringify(err));
                }
            });
            dd.ui.pullToRefresh.enable({
                onSuccess: function() {
                },
                onFail: function() {
                }
            })

            dd.biz.navigation.setMenu({
                backgroundColor : "#ADD8E6",
                items : [
                    {
                        id:"此处可以设置帮助",//字符串
                        // "iconId":"file",//字符串，图标命名
                        text:"帮助"
                    }
                    ,
                    {
                        "id":"2",
                        "iconId":"photo",
                        "text":"我们"
                    }
                    ,
                    {
                        "id":"3",
                        "iconId":"file",
                        "text":"你们"
                    }
                    ,
                    {
                        "id":"4",
                        "iconId":"time",
                        "text":"他们"
                    }
                ],
                onSuccess: function(data) {
                    alert(JSON.stringify(data));

                },
                onFail: function(err) {
                    alert(JSON.stringify(err));
                }
            });


            dd.runtime.permission.requestAuthCode({
                corpId : _config.corpId,
                onSuccess : function(info) {
			alert('authcode: ' + info.code);
                    $.ajax({
                        url : 'userinfo?code=' + info.code + '&corpid='
                        + _config.corpId,
                        type : 'GET',
                        success : function(data, status, xhr) {
                            alert(data);
                            /**
                            var info = JSON.parse(data);

                            document.getElementById("userName").innerHTML = info.name;
                            document.getElementById("userId").innerHTML = info.userid;

                            // 图片
                            if(info.avatar.length != 0){
                                var img = document.getElementById("userImg");
                                img.src = info.avatar;
                                img.height = '100';
                                img.width = '100';
                            }
                             **/

                        },
                        error : function(xhr, errorType, error) {
                            logger.e("yinyien:" + _config.corpId);
                            alert(errorType + ', ' + error);
                        }
                    });

                },
                onFail : function(err) {
                    alert('fail: ' + JSON.stringify(err));
                }
            });
        });

        dd.error(function(err) {
            alert('dd error: ' + JSON.stringify(err));
        });

    </script>
</head>
<body>
中国人就该扬眉吐气
</body>
</html>